*Title: Delivering remote learning using a low-tech solution: Evidence from an RCT during school closures  
*Author: Liang Choon Wang, Michael Vlassopoulos, Asad Islam, Hashibul Hassan 

*These codes generate Table 1, 2, 3, 4, and 5 of the main paper

***************************************************************************************
*Stata preparation - Only run once 
***************************************************************************************
*ssc install omegacoef, replace
*ssc install wyoung, replace 
*ssc install randcmd, replace 

***************************************************************************************
*Number of Replication - for FWER & RI p-values
*To run FWER and RI p-values estimates, please activate these sections by removing '/'.
***************************************************************************************
local reps = 5000

***************************************************************************************
*Setting up Directory
***************************************************************************************
cd ..
pwd
use "Data\IVR_Data.dta", clear
cd "Output"

***************************************************************************************
*TABLE 1. Sample characteristics and balance at endline 
***************************************************************************************
putexcel set "Table 1.xlsx", replace 
putexcel A1 = "Variable"	B1 = "(1) T1: Standard"	C1 = "(2) T2: Extended" D1 = "(3) T3: Control" E1 = "(4) Pairwise t-test (T1 vs. T2)" F1 = "(5) Pairwise t-test (T1 vs. C)" G1 = "(6) Pairwise t-test (T2 vs. C)"

putexcel 	A2 	= "Children's Age in years (as of 01/01/2021)" ///
			A3 	= "Gender (1 if Boy)" ///
			A4 	= "Baseline literacy score" /// 
			A5 	= "Baseline numeracy score" ///
			A6 	= "Access to private tuition" ///
			A7 	= "Father's education (in years of schooling)" /// 
			A8 	= "Mother's education (in years of schooling)" ///
			A9 	= "No. of household member" /// 
			A10 = "Family income (in BDT/ month)" ///
			A11 = "Access to TV (1 if yes)" ///
			A12	= "Access to smartphone (1 if yes)" /// 
			A13	= "Homestead land (in decimal)" ///
			A14	= "Religion (1 if Islam)" ///
			A15 = "Observations" ///
			A16 = "Village"

local baseline_characteristics 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

local j = 2 

foreach v of local baseline_characteristics {

regress `v' standard_treat extended_treat control_group if endline_completed == 1, nocons r cluster(VILLAGE_ID)

putexcel set "Table 1.xlsx", modify 

local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
putexcel B`j' 	= "`mean' (`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
putexcel C`j' 	= "`mean' (`se')"

local mean 		= string(_b[control_group],"%9.2f")
local se 		= string(_se[control_group],"%9.2f")
putexcel D`j' 	= "`mean' (`se')"

ttest `v' if treatment_arms != 3 & endline_completed == 1, by(standard_treat)
local pval		= string(`r(p)',"%9.2f")
putexcel E`j' 	= "`pval'"

ttest `v' if treatment_arms != 2 & endline_completed == 1, by(standard_treat)
local pval		= string(`r(p)',"%9.2f")
putexcel F`j' 	= "`pval'"

ttest `v' if treatment_arms != 1 & endline_completed == 1, by(extended_treat)
local pval		= string(`r(p)',"%9.2f")
putexcel G`j' 	= "`pval'"

local j = `j' + 1
}

distinct RECORD_ID if treatment_arms == 1 & endline_completed == 1
putexcel B15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms == 1 & endline_completed == 1
putexcel B16	= (r(ndistinct))

distinct RECORD_ID if treatment_arms == 2 & endline_completed == 1
putexcel C15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms == 2 & endline_completed == 1
putexcel C16	= (r(ndistinct))

distinct RECORD_ID if treatment_arms == 3 & endline_completed == 1
putexcel D15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms == 3 & endline_completed == 1
putexcel D16	= (r(ndistinct))

distinct RECORD_ID if treatment_arms != 3 & endline_completed == 1
putexcel E15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms != 3 & endline_completed == 1
putexcel E16	= (r(ndistinct))

distinct RECORD_ID if treatment_arms != 2 & endline_completed == 1
putexcel F15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms != 2 & endline_completed == 1
putexcel F16	= (r(ndistinct))

distinct RECORD_ID if treatment_arms != 1 & endline_completed == 1
putexcel G15	= "`r(N)' (`r(ndistinct)')"

distinct VILLAGE_ID if treatment_arms != 1 & endline_completed == 1
putexcel G16	= (r(ndistinct))

putexcel (B1:G16), hcenter vcenter

***************************************************************************************
*TABLE 2. FWER and RI p-values estimation
***************************************************************************************
global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

putexcel set "Table 2.xlsx", replace 
putexcel 	A1 = "Variable" B1 = "(1) Control mean" C1 = "T1: Standard"	E1 = "T2: Extended" 
putexcel	C2 = "(2) Treatment effect (Total score)" D2 = "(3) Treatment effect (SD)"
putexcel	E2 = "(4) Treatment effect (Total score)" F2 = "(5) Treatment effect (SD)"

putexcel 	A3 	= "Total score" A4 	= "Literacy" A5 = "Numeracy" ///
			A6 	= "Overall impulsivity" A7 = "Schoolwork impulsivity" A8 = "Interpersonal impulsivity" ///
			A9 	= "Girt score" A10 = "Growth mindset" ///
			A11	= "Affective empathy (contagion)" A12 = "Cognitive empathy (understanding)" ///
			A13 = "Prosocial motivation (support)" ///
			A14 = "Leadership" A15 = "Communication" A16 = "Planning" ///
			A17	= "Emotional symptoms" A18 = "Conduct problem" A19 = "Hyperactivity" ///
			A20 = "Peer problem" A21 = "Prosocial"
			
putexcel (C1:D1) (E1:F1) (A1:A2) (B1:B2), merge hcenter

local outcome_vars 	endline_total_score endline_literacy_score endline_numeracy_score impulsivity_overall impulsivity_schoolwork impulsivity_interpersonal grit gms affective_empathy cognitive_empathy prosocial_empathy leadership communication planning sdq_emotion sdq_conduct sdq_hyper sdq_peer sdq_prosocial

local j = 3

foreach v of local outcome_vars {

regress `v' standard_treat extended_treat control_group if endline_completed == 1, nocons r cluster(VILLAGE_ID)

putexcel set "Table 2.xlsx", modify 

local mean		= string(_b[control_group],"%9.2f")
local se 		= string(_se[control_group],"%9.2f")
putexcel B`j' 	= "`mean'(`se')"

regress `v' standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r cluster(VILLAGE_ID)

local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E`j' 	= "`mean'`sig'(`se')"


local j = `j' + 1
}

local std_outcome_vars 	endline_total_score_std endline_literacy_score_std endline_numeracy_score_std impulsivity_overall_std impulsivity_schoolwork_std impulsivity_interpersonal_std grit_std gms_std affective_empathy_std cognitive_empathy_std prosocial_empathy_std leadership_std communication_std planning_std sdq_emotion_std sdq_conduct_std sdq_hyper_std sdq_peer_std sdq_prosocial_std

local j = 3 

foreach v of local std_outcome_vars {
regress `v' standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r cluster(VILLAGE_ID)
 
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F`j' 	= "`mean'`sig'(`se')"

local j = `j' + 1
}

/*************************************************************************************
*TABLE 2_MHT. Treatment effects on key outcomes - FWER & RI p-values
***************************************************************************************
global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

*westfall-young p-values - Raw outcomes
putexcel set "Table 2_MHT_Raw.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"		D1 = "T2: Extended"
putexcel 	(B1:C1) (D1:E1), merge vcenter hcenter
putexcel 	B2 = "FWER P-value" C2 = "RI P-value" D2 = "FWER P-value" E2 = "RI P-value"

putexcel 	A3 	= "Total score" A4 	= "Literacy" A5 = "Numeracy" ///
			A6 	= "Overall impulsivity" A7 = "Schoolwork impulsivity" A8 = "Interpersonal impulsivity" ///
			A9 	= "Girt score" A10 = "Growth mindset" ///
			A11	= "Affective empathy (contagion)" A12 = "Cognitive empathy (understanding)" ///
			A13 = "Prosocial motivation (support)" ///
			A14 = "Leadership" A15 = "Communication" A16 = "Planning" ///
			A17	= "Emotional symptoms" A18 = "Conduct problem" A19 = "Hyperactivity" ///
			A20 = "Peer problem" A21 = "Prosocial"


wyoung 	endline_total_score endline_literacy_score endline_numeracy_score impulsivity_overall impulsivity_schoolwork impulsivity_interpersonal grit gms affective_empathy cognitive_empathy prosocial_empathy leadership communication planning sdq_emotion sdq_conduct sdq_hyper sdq_peer sdq_prosocial, ///
cmd(areg OUTCOMEVAR standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r a(child_grade_std) cluster(VILLAGE_ID)) familyp(standard_treat extended_treat) bootstraps(`reps') seed(1234) cluster(VILLAGE_ID) 

putexcel set "Table 2_MHT_Raw.xlsx", modify

local j = 3
forvalues v = 1/19 {
matrix emat =	r(table)
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel B`j' 	= "`wypval'"
local j = `j'+1
}

local j = 3
forvalues v = 20/38 {
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel D`j' 	= "`wypval'"
local j = `j'+1
}

*Randomization inference p-values - raw outcomes 
 randcmd((standard_treat extended_treat) areg endline_total_score standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg endline_literacy_score standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		((standard_treat extended_treat) areg endline_numeracy_score standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_overall standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_schoolwork standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_interpersonal standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg grit standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg gms standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg affective_empathy standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg cognitive_empathy standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg prosocial_empathy standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg leadership standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg communication standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg planning standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_emotion standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_conduct standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_hyper standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_peer standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_prosocial standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		, treatvars(standard_treat extended_treat) reps(`reps')

local j = 3
forvalues v = 1(2)38 {
matrix emat = e(RCoef)
local ri 	= string(emat[`v',6],"%9.2f")
putexcel C`j' 	= "`ri'"
local j = `j' + 1
}		
			
local j = 3
forvalues v = 2(2)38 {
local ri 		= string(emat[`v',6],"%9.2f")
putexcel E`j' 	= "`ri'"
local j = `j' + 1
}
putexcel (B3:I21), hcenter vcenter

*westfall-young p-values - Standardized outcomes
putexcel set "Table 2_MHT_SD.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"		D1 = "T2: Extended"
putexcel 	(B1:C1) (D1:E1), merge vcenter hcenter
putexcel 	B2 = "FWER P-value" C2 = "RI P-value" D2 = "FWER P-value" E2 = "RI P-value"

putexcel 	A3 	= "Total score" A4 	= "Literacy" A5 = "Numeracy" ///
			A6 	= "Overall impulsivity" A7 = "Schoolwork impulsivity" A8 = "Interpersonal impulsivity" ///
			A9 	= "Girt score" A10 = "Growth mindset" ///
			A11	= "Affective empathy (contagion)" A12 = "Cognitive empathy (understanding)" ///
			A13 = "Prosocial motivation (support)" ///
			A14 = "Leadership" A15 = "Communication" A16 = "Planning" ///
			A17	= "Emotional symptoms" A18 = "Conduct problem" A19 = "Hyperactivity" ///
			A20 = "Peer problem" A21 = "Prosocial"

wyoung 	endline_total_score_std endline_literacy_score_std endline_numeracy_score_std impulsivity_overall_std impulsivity_schoolwork_std impulsivity_interpersonal_std grit_std gms_std affective_empathy_std cognitive_empathy_std prosocial_empathy_std leadership_std communication_std planning_std 					sdq_emotion_std sdq_conduct_std sdq_hyper_std sdq_peer_std sdq_prosocial_std, ///
cmd(areg OUTCOMEVAR standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r a(child_grade_std) cluster(VILLAGE_ID)) familyp(standard_treat extended_treat) bootstraps(`reps') seed(1234) cluster(VILLAGE_ID) 

putexcel set "Table 2_MHT_SD.xlsx", modify

local j = 3
forvalues v = 1/19 {
matrix emat =	r(table)
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel B`j' 	= "`wypval'"
local j = `j'+1
}

local j = 3
forvalues v = 20/38 {
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel D`j' 	= "`wypval'"
local j = `j'+1
}

*Randomization inference p-values - standardized outcomes 
 randcmd((standard_treat extended_treat) areg endline_total_score_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg endline_literacy_score_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		((standard_treat extended_treat) areg endline_numeracy_score_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_overall_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_schoolwork_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg impulsivity_interpersonal_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg grit_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg gms_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg affective_empathy_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg cognitive_empathy_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg prosocial_empathy_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg leadership_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg communication_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg planning_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_emotion_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_conduct_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_hyper_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_peer_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg sdq_prosocial_std standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		, treatvars(standard_treat extended_treat) reps(`reps')

local j = 3
forvalues v = 1(2)38 {
matrix emat = e(RCoef)
local ri 	= string(emat[`v',6],"%9.2f")
putexcel C`j' 	= "`ri'"
local j = `j' + 1
}		
			
local j = 3
forvalues v = 2(2)38 {
local ri 		= string(emat[`v',6],"%9.2f")
putexcel E`j' 	= "`ri'"
local j = `j' + 1
}
putexcel (B3:I21), hcenter vcenter
*/

***************************************************************************************
*TABLE 3. Heterogenous treatment effects on learning and homeschooling
***************************************************************************************
putexcel set "Table 3.xlsx", replace
putexcel 	A1 = "Variables"	B1 = "W: Gender"	E1 = "X: Baseline score" ///
			H1= "Y: Household income" K1 = "Z: Parental education"
putexcel 	(A1:A2) (B1:D1) (E1:G1) (H1:J1) (K1:M1), merge hcenter vcenter
putexcel 	B2 = "(1) Boy" C2 = "(2) Girl" D2 = "(3) Interaction" E2 = "(4) Above median" ///
			F2 = "(5) Below median" G2 = "(6) Interaction" H2 = "(7) Above median" I2 = "(8) Below median" ///
			J2 = "(9) Interaction"  K2 = "(10) Above median" L2 = "(11) Below median" M2 = "(12) Interaction" 

putexcel 	A3 = "Panel A: Standard treatment" A4 = "Total score" A5 = "Literacy" A6 = "Numeracy" ///
			A7 = "Student's study time" A8 = "Caregiver's time in homeschooling" A9 = "Observations"
			
putexcel 	A10 = "Panel B: Extended treatment" A11 = "Total score" A12 = "Literacy" A13 = "Numeracy" /// 
			A14 = "Student's study time" A15 = "Caregiver's time in homeschooling" A16 = "Observations" 

putexcel (A3:M3) (A10:M10), merge 

***************************
*Gender
***************************
global 	gen_het_control_list 	child_age baseline_literacy_score baseline_numeracy_score child_pvt_tuition 			father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

local 	outvar 	endline_total_score_std endline_literacy_score_std endline_numeracy_score_std study_time_child_std homeschooling_time_std

local j = 4 

foreach var of local outvar {

regress `var' 	i.standard_treat i.child_gen standard_treat##child_gen $gen_het_control_list i.child_grade_std /// 
				if endline_completed == 1 & extended_treat == 0 & child_gen==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel B`j' 	= "`mean'`sig' (`se')"
putexcel B9		= `e(N)'

regress `var' 	i.standard_treat i.child_gen standard_treat##child_gen $gen_het_control_list i.child_grade_std ///
				if endline_completed == 1 & extended_treat == 0  & child_gen==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C`j' 	= "`mean'`sig' (`se')"
putexcel C9		= `e(N)'

regress `var' 	i.standard_treat i.child_gen standard_treat##child_gen $gen_het_control_list i.child_grade_std ///
				if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.child_gen],"%9.2f")
local se 		= string(_se[1.standard_treat#1.child_gen],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D`j' 	= "`mean'`sig' (`se')"
putexcel D9		= `e(N)'

local j = `j' + 1
}

local j = 11

foreach var of local outvar {

regress `var' 	i.extended_treat i.child_gen extended_treat##child_gen $gen_het_control_list i.child_grade_std /// 
				if endline_completed == 1 & standard_treat == 0 & child_gen==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel B`j' 	= "`mean'`sig' (`se')"
putexcel B16	= `e(N)'

regress `var' 	i.extended_treat i.child_gen extended_treat##child_gen $gen_het_control_list i.child_grade_std /// 
				if endline_completed == 1 & standard_treat == 0 & child_gen==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C`j' 	= "`mean'`sig' (`se')"
putexcel C16	= `e(N)'

regress `var' 	i.extended_treat i.child_gen extended_treat##child_gen $gen_het_control_list i.child_grade_std /// 
				if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.child_gen],"%9.2f")
local se 		= string(_se[1.extended_treat#1.child_gen],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D`j' 	= "`mean'`sig' (`se')"
putexcel D16	= `e(N)'

local j = `j' + 1
}

***************************
*Baseline Score
***************************
egen 	baseline_result = rowtotal(baseline_literacy_score baseline_numeracy_score)
todummy baseline_result if endline_completed == 1, median

global res_het_control_list child_gen child_age child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

local j = 4 

foreach var of local outvar {

regress `var' i.standard_treat i.d_baseline_result standard_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_baseline_result==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E`j' 	= "`mean'`sig' (`se')"
putexcel E9		= `e(N)'

regress `var' i.standard_treat i.d_baseline_result standard_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_baseline_result==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F`j' 	= "`mean'`sig' (`se')"
putexcel F9		= `e(N)'

regress `var' 	i.standard_treat i.d_baseline_result standard_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.d_baseline_result],"%9.2f")
local se 		= string(_se[1.standard_treat#1.d_baseline_result],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel G`j' 	= "`mean'`sig' (`se')"
putexcel G9		= `e(N)'

local j = `j' + 1
}

local j = 11

foreach var of local outvar {

regress `var' 	i.extended_treat i.d_baseline_result extended_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_baseline_result==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E`j' 	= "`mean'`sig' (`se')"
putexcel E16	= `e(N)'

regress `var' 	i.extended_treat i.d_baseline_result extended_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_baseline_result==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F`j'	= "`mean'`sig' (`se')"
putexcel F16	= `e(N)'

regress `var' i.extended_treat i.d_baseline_result extended_treat##d_baseline_result $res_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.d_baseline_result],"%9.2f")
local se 		= string(_se[1.extended_treat#1.d_baseline_result],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel G`j' 	= "`mean'`sig' (`se')"
putexcel G16	= `e(N)'

local j = `j' + 1
}

***************************
*Family income
***************************
global income_het_control_list 	child_gen child_age baseline_literacy_score baseline_numeracy_score child_pvt_tuition /// 
								father_edu_years mother_edu_years hh_mem  television smartphone hs_land reli_dummy

todummy family_income if endline_completed == 1, median

local j = 4 

foreach var of local outvar {

regress `var' 	i.standard_treat i.d_family_income standard_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_family_income==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel H`j'	= "`mean'`sig' (`se')"
putexcel H9		= `e(N)'

regress `var' 	i.standard_treat i.d_family_income standard_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_family_income==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel I`j' 	= "`mean'`sig' (`se')"
putexcel I9		= `e(N)'

regress `var' 	i.standard_treat i.d_family_income standard_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.d_family_income],"%9.2f")
local se 		= string(_se[1.standard_treat#1.d_family_income],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel J`j' 	= "`mean'`sig' (`se')"
putexcel J9		= `e(N)'

local j = `j' + 1
}

local j = 11

foreach var of local outvar {

regress `var' 	i.extended_treat i.d_family_income extended_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_family_income==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel H`j'	= "`mean'`sig' (`se')"
putexcel H16	= `e(N)'

regress `var' 	i.extended_treat i.d_family_income extended_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_family_income==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel I`j' 	= "`mean'`sig' (`se')"
putexcel I16	= `e(N)'

regress `var' 	i.extended_treat i.d_family_income extended_treat##d_family_income $income_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.d_family_income],"%9.2f")
local se 		= string(_se[1.extended_treat#1.d_family_income],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel J`j'	= "`mean'`sig' (`se')"
putexcel J16	= `e(N)'

local j = `j' + 1
}

***************************
*Parental Education
***************************
global edu_het_control_list 	child_gen child_age baseline_literacy_score baseline_numeracy_score child_pvt_tuition hh_mem family_income television smartphone hs_land reli_dummy

local j = 4 

foreach var of local outvar {

regress `var' 	i.standard_treat i.d_parent_edu standard_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_parent_edu==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel K`j'	= "`mean'`sig' (`se')"
putexcel K9		= `e(N)'

regress `var' 	i.standard_treat i.d_parent_edu standard_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0 & d_parent_edu==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat],"%9.2f")
local se 		= string(_se[1.standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel L`j' 	= "`mean'`sig' (`se')"
putexcel L9		= `e(N)'

regress `var' 	i.standard_treat i.d_parent_edu standard_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & extended_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.standard_treat#1.d_parent_edu],"%9.2f")
local se 		= string(_se[1.standard_treat#1.d_parent_edu],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel M`j' 	= "`mean'`sig' (`se')"
putexcel M9		= `e(N)'

local j = `j' + 1
}

local j = 11

foreach var of local outvar {

regress `var' 	i.extended_treat i.d_parent_edu extended_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_parent_edu==1, r cluster(VILLAGE_ID)

putexcel set "Table 3.xlsx", modify
local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel K`j'	= "`mean'`sig' (`se')"
putexcel K16		= `e(N)'

regress `var' 	i.extended_treat i.d_parent_edu extended_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0 & d_parent_edu==0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat],"%9.2f")
local se 		= string(_se[1.extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel L`j' 	= "`mean'`sig' (`se')"
putexcel L16	= `e(N)'

regress `var' 	i.extended_treat i.d_parent_edu extended_treat##d_parent_edu $edu_het_control_list i.child_grade_std if endline_completed == 1 & standard_treat == 0, r cluster(VILLAGE_ID)

local mean 		= string(_b[1.extended_treat#1.d_parent_edu],"%9.2f")
local se 		= string(_se[1.extended_treat#1.d_parent_edu],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,8], "%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel M`j' 	= "`mean'`sig' (`se')"
putexcel M16	= `e(N)'

local j = `j' + 1
}

putexcel (B4:M9) (B11:M16) (B2:M2), vcenter hcenter 

***************************************************************************************
*TABLE 4. Treatment effect on homeschooling outcomes
***************************************************************************************
putexcel set "Table 4.xlsx", replace 
putexcel 	A1 = "Variable" B1 = "(1) Control mean" 	C1 = "T1: Standard"	E1 = "T2: Extended" 
putexcel	C2 = "(2) Treatment effect (Total score)" 	D2 = "(3) Treatment effect (SD)"
putexcel	E2 = "(4) Treatment effect (Total score)" 	F2 = "(5) Treatment effect (SD)"

putexcel 	A3 	= "Student's study time" 				A4 	= "Extent of study" ///
			A5 	= "Caregiver's time in homeschooling" 	A6	= "Extent of caregiver's homeschooling"

putexcel (C1:D1) (E1:F1) (A1:A2) (B1:B2), merge hcenter

local outcome_vars study_time_child extent_of_study homeschooling_time extent_of_homeschooling

local j = 3 

foreach v of local outcome_vars {

regress `v' standard_treat extended_treat control_group if endline_completed == 1, nocons r cluster(VILLAGE_ID)

putexcel set "Table 4.xlsx", modify 

local mean		= string(_b[control_group],"%9.2f")
local se 		= string(_se[control_group],"%9.2f")
putexcel B`j' 	= "`mean'(`se')"

regress `v' standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r cluster(VILLAGE_ID)

local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E`j' 	= "`mean'`sig'(`se')"

local j = `j' + 1
}

local std_outcome_vars study_time_child_std extent_of_study_std homeschooling_time_std extent_of_homeschooling_std 

local j = 3 

foreach v of local std_outcome_vars {
regress `v' standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r cluster(VILLAGE_ID)

putexcel set "Table 4.xlsx", modify 
local mean 		= string(_b[standard_treat],"%9.2f")
local se 		= string(_se[standard_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D`j' 	= "`mean'`sig'(`se')"

local mean 		= string(_b[extended_treat],"%9.2f")
local se 		= string(_se[extended_treat],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F`j' 	= "`mean'`sig'(`se')"

local j = `j' + 1
}

/***************************************************************************************
*TABLE 4_MHT. Treatment effect on homeschooling outcomes - FWER & RI p-values
***************************************************************************************
global control_list 	child_age child_gen baseline_literacy_score baseline_numeracy_score child_pvt_tuition father_edu_years mother_edu_years hh_mem family_income television smartphone hs_land reli_dummy

*westfall-young p-values - Raw Outcomes
putexcel set "Table 4_MHT_Raw.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"		D1 = "T2: Extended"
putexcel 	(B1:C1) (D1:E1), merge vcenter hcenter
putexcel 	B2 = "FWER P-value" C2 = "RI P-value" D2 = "FWER P-value" E2 = "RI P-value"

putexcel 	A3 	= "Student's study time" 				A4 	= "Extent of study" ///
			A5 	= "Caregiver's time in homeschooling" 	A6	= "Extent of caregiver's homeschooling"
			
wyoung 	study_time_child extent_of_study homeschooling_time extent_of_homeschooling, cmd(areg OUTCOMEVAR standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r a(child_grade_std) cluster(VILLAGE_ID)) familyp(standard_treat extended_treat) bootstraps(`reps') seed(1234) cluster(VILLAGE_ID) 

putexcel set "Table 4_MHT_Raw.xlsx", modify 

local j = 3
forvalues v = 1/4 {
matrix emat =	r(table)
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel B`j' 	= "`wypval'"
local j = `j'+1
}

local j = 3
forvalues v = 5/8 {
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel D`j' 	= "`wypval'"
local j = `j'+1
}

*Randomization inference p-values - raw outcomes
 randcmd((standard_treat extended_treat) areg study_time_child 	standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg extent_of_study 	standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		((standard_treat extended_treat) areg homeschooling_time 		standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg extent_of_homeschooling 		standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)), /// 
		 treatvars(standard_treat extended_treat) reps(`reps')

local j = 3
forvalues v = 1(2)8 {
matrix emat = e(RCoef)
local ri 	= string(emat[`v',6],"%9.2f")
putexcel C`j' 	= "`ri'"
local j = `j' + 1
}		
			
local j = 3
forvalues v = 2(2)8 {
local ri 		= string(emat[`v',6],"%9.2f")
putexcel E`j' 	= "`ri'"
local j = `j' + 1
}

*westfall-young p-values - standardized Outcomes 
putexcel set "Table 4_MHT_SD.xlsx", replace 
putexcel 	A1 = "Variables"	B1 = "T1: Standard"		D1 = "T2: Extended"
putexcel 	(B1:C1) (D1:E1), merge vcenter hcenter
putexcel 	B2 = "FWER P-value" C2 = "RI P-value" D2 = "FWER P-value" E2 = "RI P-value"

putexcel 	A3 	= "Student's study time" 				A4 	= "Extent of study" ///
			A5 	= "Caregiver's time in homeschooling" 	A6	= "Extent of caregiver's homeschooling"
			
wyoung 	study_time_child_std extent_of_study_std homeschooling_time_std extent_of_homeschooling_std, cmd(areg OUTCOMEVAR standard_treat extended_treat $control_list i.child_grade_std if endline_completed == 1, r a(child_grade_std) cluster(VILLAGE_ID)) familyp(standard_treat extended_treat) bootstraps(`reps') seed(1234) cluster(VILLAGE_ID) 

putexcel set "Table 4_MHT_SD.xlsx", modify 

local j = 3
forvalues v = 1/4 {
matrix emat =	r(table)
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel B`j' 	= "`wypval'"
local j = `j'+1
}

local j = 3
forvalues v = 5/8 {
local wypval 	= string(emat[(`v'),4],"%9.2f")
putexcel D`j' 	= "`wypval'"
local j = `j'+1
}

*Randomization inference p-values - standardized Outcomes
 randcmd((standard_treat extended_treat) areg study_time_child_std 	standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg extent_of_study_std 	standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) ///
		((standard_treat extended_treat) areg homeschooling_time_std 		standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)) /// 
		((standard_treat extended_treat) areg extent_of_homeschooling_std 		standard_treat extended_treat $control_list i.child_grade_std if endline_completed==1, r a(child_grade_std) cluster(VILLAGE_ID)), /// 
		 treatvars(standard_treat extended_treat) reps(`reps')

local j = 3
forvalues v = 1(2)8 {
matrix emat = e(RCoef)
local ri 	= string(emat[`v',6],"%9.2f")
putexcel C`j' 	= "`ri'"
local j = `j' + 1
}		
			
local j = 3
forvalues v = 2(2)8 {
local ri 		= string(emat[`v',6],"%9.2f")
putexcel E`j' 	= "`ri'"
local j = `j' + 1
}
*/

***************************************************************************************
*TABLE 5. Relationships between types of lesson completion and baseline characteristics
***************************************************************************************
global baseline_x "child_age child_gen child_pvt_tuition hh_mem reli_dummy television smartphone hs_land"

putexcel set "Table 5.xlsx", replace
putexcel A1 = "Variables" B1 = "X: Following sequence without skipping" D1 = "Y: Total number of lessons completed" F1 = "Z: Percent of completed lessons ever repeated"

putexcel B2 = "(1) Literacy" C2 = "(2) Numeracy" D2 = "(3) Literacy" E2 = "(4) Numeracy" F2 = "(5) Literacy" G2 = "(6) Numeracy"

putexcel A3 = "Less-educated parents" A4 = "Lower baseline score" A5 = "Lower household income" A6 = "Observations" A7 = "R-squared"

putexcel (A1:A2) (B1:C1) (D1:E1) (F1:G1), merge hcenter vcenter

reg sequence_lit low_parent low_base_lit low_family_inc $baseline_x if any_treat==1 & endline_completed==1, cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel B3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_lit],"%9.2f")
local se 		= string(_se[low_base_lit],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel B4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel B5 	= "`mean'`sig'(`se')"

putexcel B6 = `e(N)'
putexcel B7 = `e(r2)', nformat(number_d2)

reg sequence_num low_parent low_base_num low_family_inc $baseline_x if any_treat==1 & endline_completed==1, cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_num],"%9.2f")
local se 		= string(_se[low_base_num],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel C5 	= "`mean'`sig'(`se')"

putexcel C6 = `e(N)'
putexcel C7 = `e(r2)', nformat(number_d2)

reg totlessons_lit low_parent low_base_lit low_family_inc $baseline_x if any_treat==1 & endline_completed==1, cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_lit],"%9.2f")
local se 		= string(_se[low_base_lit],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel D5 	= "`mean'`sig'(`se')"

putexcel D6 = `e(N)'
putexcel D7 = `e(r2)', nformat(number_d2)

reg totlessons_num low_parent low_base_num low_family_inc $baseline_x if any_treat==1 & endline_completed==1, cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_num],"%9.2f")
local se 		= string(_se[low_base_num],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel E5 	= "`mean'`sig'(`se')"

putexcel E6 = `e(N)'
putexcel E7 = `e(r2)', nformat(number_d2)


reg reppct_lit low_parent low_base_lit low_family_inc $baseline_x if any_treat==1 & endline_completed==1, cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_lit],"%9.2f")
local se 		= string(_se[low_base_lit],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel F5 	= "`mean'`sig'(`se')"

putexcel F6 = `e(N)'
putexcel F7 = `e(r2)', nformat(number_d2)

reg reppct_num low_parent low_base_num low_family_inc $baseline_x if any_treat==1 & endline_completed==1., cl(VILLAGE)

local mean 		= string(_b[low_parent],"%9.2f")
local se 		= string(_se[low_parent],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,1],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel G3 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_base_num],"%9.2f")
local se 		= string(_se[low_base_num],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,2],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel G4 	= "`mean'`sig'(`se')"

local mean 		= string(_b[low_family_inc],"%9.2f")
local se 		= string(_se[low_family_inc],"%9.2f")
matrix emat		= r(table)
local pval		= string(emat[4,3],"%9.4f")
local sig		= cond(`pval' < 0.001, "***", cond(`pval' < 0.01, "**", cond(`pval' < 0.05, "*", "")))
putexcel G5 	= "`mean'`sig'(`se')"

putexcel G6 = `e(N)'
putexcel G7 = `e(r2)', nformat(number_d2)

clear 